//
//  UIImage+Helper.m
//  Local
//
//  Created by 刘铎 on 13-12-9.
//  Copyright (c) 2013年 上海即略网络信息科技有限公司. All rights reserved.
//

#import "UIImage+Helper.h"

@implementation UIImage (Helper)

+ (UIImage *)imageNamed:(NSString *)name resizableImageWithCapInsets:(UIEdgeInsets)capInsets {
    if ([[[UIDevice currentDevice] systemVersion] floatValue]
 >= 5.0) {
        return [[UIImage imageNamed:name] resizableImageWithCapInsets:capInsets];
    } else if ([[[UIDevice currentDevice] systemVersion] floatValue] == 4.3) {
        return [[UIImage imageNamed:name] stretchableImageWithLeftCapWidth:capInsets.left topCapHeight:capInsets.top];
    } else {
        return nil;
    }
}
-(UIImage*)imageWithNewSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    
    // Tell the old image to draw in this new context, with the desired
    // new size
    [self drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    
    // Return the new image.
    return newImage;
}

@end
